package com.eugenema.runMain;

import com.eugenema.service.ScanAnnotationService;
import com.eugenema.service.UpdateService;
import com.eugenema.util.LoggerListener;
import com.eugenema.util.SeleniumUtil;
import com.eugenema.windowGui.MainApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 启动类
 *
 * @author Eugenema
 * @date 2023/3/14 21:39
 */
public class StartMain {
    /** 日志 */
    private static Logger logger = LoggerFactory.getLogger(StartMain.class);
    /** 线程池 */
    public static ExecutorService threadPool = Executors.newFixedThreadPool(10);
    /** 扫描注解服务 */
    private static ScanAnnotationService scanAnnotationService = new ScanAnnotationService();

    /**
     * 主方法
     * 启动界面，根源控制异常抓捕及关闭浏览器及线程池
     *
     * @param args
     * @author Eugenema
     * @date 2023/4/2 21:48
     **/
    public static void main(String[] args) {
        try {
            //启动日志监控
            LoggerListener.runMonitor();
            // 初始化版本信息
            UpdateService.initVersion();
            // 扫描注解
            scanAnnotationService.scanDemand();
            //启动界面
            MainApplication.main(args);
        } catch (Exception exception) {
            logger.error("执行失败：", exception);
        }
    }

    /**
     * 关闭程序
     *
     * @author Eugenema
     * @date 2023/4/13 22:32
     **/
    public static void closeProgram() {
        //关闭浏览器
        SeleniumUtil.quitBrowser();
        //关闭线程池
        threadPool.shutdownNow();
        //关闭文件监听
        LoggerListener.stopMonitor();
        // 强行关闭程序
        System.exit(0);
    }
}
